package com.app.bimo.commonbusiness.view;

import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.app.bimo.commonbusiness.R;
import com.app.bimo.commonbusiness.util.DataUtil;

import androidx.annotation.NonNull;

public class ShareDialog extends Dialog implements View.OnClickListener {
    private TextView shareTitle;
    private TextView friends;
    private TextView wechat;
    private TextView qq;
    private TextView qzone;
    private TextView weibo;
    private TextView cancel;
    private ShareClickListener listener;

    public ShareDialog(@NonNull Context context) {
        this(context, R.style.MyDialogStyle_Animation_bg);
    }

    public ShareDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    public void setListener(ShareClickListener listener) {
        this.listener = listener;
    }

    private void initView(Context context) {
        View view = View.inflate(context, R.layout.view_share, null);
        setContentView(view);
        shareTitle = view.findViewById(R.id.shareTitle);
        friends = view.findViewById(R.id.friends);
        qq = view.findViewById(R.id.qq);
        wechat = view.findViewById(R.id.wechat);
        qzone = view.findViewById(R.id.qzone);
        weibo = view.findViewById(R.id.weibo);
        cancel = view.findViewById(R.id.cancel);

        qq.setOnClickListener(this);
        wechat.setOnClickListener(this);
        qzone.setOnClickListener(this);
        cancel.setOnClickListener(this);
        friends.setOnClickListener(this);
        weibo.setOnClickListener(this);

        WindowManager.LayoutParams localLayoutParams = getWindow()
                .getAttributes();
        localLayoutParams.gravity = Gravity.BOTTOM;
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(localLayoutParams);

    }

    public void setShareTitleTv(String shareTitleTv) {
        if (DataUtil.isEmpty(shareTitleTv)) {
//            shareTitleTv = "成功分享至以下渠道，奖励<font color='#f7cf78'>10墨点</font>";
            shareTitleTv = "分享";
            shareTitle.setText(Html.fromHtml(shareTitleTv));
        } else {
            shareTitle.setText(shareTitleTv);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
//        if (i == R.id.cancel) {
//        }
        if (listener != null) {
            dismiss();
            listener.click(id);

        }


    }

    public interface ShareClickListener {
        void click(int id);
    }

}
